<?php
namespace app\wx\controller;

class Index
{   
    /**
     * 微信入口
     */
    public function index()
    {
        $msg  = new \app\common\model\Msg();
        $wx   = \app\common\model\Wx::getObj();
        $user = new \app\common\model\User();
        
        #验证
        //if( $wx->checkSignature() ) exit($_GET['echostr']);
        //$wx->valid();
        
        
        #路由
        $type = $wx->getRev()->getRevType();
        $d    = $wx->getRevData();
        //t($d);
        com_log($d,'wx');
        switch($type) {
            #事件
            case 'event':
                switch ($d['Event']){
                    case 'subscribe':#关注
                        $user->followMp( $wx->getRevFrom() );
                        $wx->text( $msg->getReplayFocus(1) )->reply();
                        break;
                    case 'unsubscribe':#取消
                        $user->cancelMp( $wx->getRevFrom() );
                        break; 
                    case 'CLICK':#点击菜单
                        if(isset($d['key'])){
                            switch($d['key']){
                                case 'goods': #回复今日折扣
                                    $g = new \app\common\model\Goods();
                                    $g->sendRec7( $wx->getRevFrom() );
                                    break;
                                case 'qiandao': #回复签到积分                                    
                                    $wx->text( '签到积分正在开发' )->reply();
                                    break;
                            }
                        }
                        break;
                }
                break;
            #关键词回复
            case 'text':
                $k = new \app\common\model\Keyword();
                $k->doit( $wx->getRevContent() );
                break;
            #                
            default:
      			$wx->text("help info")->reply(); 
        }
        exit;   
    }
}
